#include "driver/gpio.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

#define LED_GPIO GPIO_NUM_8

void led_on(void)
{
    gpio_set_level(LED_GPIO, 1);
}

void led_off(void)
{
    gpio_set_level(LED_GPIO, 0);
}

void led_toggle(void)
{
    static int led_state = 1;
    led_state = !led_state;
    gpio_set_level(LED_GPIO, led_state);
    printf("LED state: %d\n", led_state);
}

void led_task(void *pvParameter)
{
    while (1)
    {
        led_on();
        vTaskDelay(pdMS_TO_TICKS(1000));
        led_off();
        vTaskDelay(pdMS_TO_TICKS(1000));
    }
}

void led_init(void)
{
    gpio_config_t io_conf = {
        .pin_bit_mask = (1ULL << LED_GPIO),  // 选择引脚
        .mode = GPIO_MODE_OUTPUT,            // 输出模式
        .pull_up_en = GPIO_PULLUP_DISABLE,   // 不上拉
        .pull_down_en = GPIO_PULLDOWN_DISABLE, // 不下拉
        .intr_type = GPIO_INTR_DISABLE       // 不用中断
    };
    gpio_config(&io_conf);
    // gpio_dump_io_configuration(stdout, SOC_GPIO_VALID_GPIO_MASK);

    // xTaskCreate(led_task, "led_task", 2048, NULL, 5, NULL);
}
